package com.zingrow.web.support.operate.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zingrow.common.utils.PageView;
import com.zingrow.web.base.service.impl.BaseService;
import com.zingrow.web.support.operate.mapper.OptRecordMapper;
import com.zingrow.web.support.operate.model.AppOptRecord;
import com.zingrow.web.support.operate.model.OptRecord;
import com.zingrow.web.support.operate.service.IOptRecordService;
import com.zingrow.web.user.model.User;

@Service
public class OptRecordService extends BaseService<User> implements IOptRecordService {
	@Autowired
	OptRecordMapper optRecordMapper;

	@Override
	public void initMapper() {
		this.baseMapper = optRecordMapper;
	}

	@Override
	public List<OptRecord> queryByParams(PageView pageView, String account, String startTime, String endTime,String channelname,String dongzname) {
		Map<String, Object> map = new HashMap<>();
		// 添加分页参数
		map.put("paging", pageView);
		// 查询参数
		if (StringUtils.isNotBlank(account)) {
			account = "%" + account + "%";
			map.put("account", account);
		}
		map.put("startTime", startTime);
		map.put("endTime", endTime);
		map.put("channelname", channelname);
		map.put("dongzname", dongzname);
		return optRecordMapper.selectByParams(map);
	}
	
	@Override
	public List<AppOptRecord> appqueryByParams(PageView pageView, String account, String startTime, String endTime,String name,String optChannel) {
		Map<String, Object> map = new HashMap<>();
		// 添加分页参数
		map.put("paging", pageView);
		// 查询参数
		if (StringUtils.isNotBlank(account)) {
			account = "%" + account + "%";
			map.put("account", account);
		}
		if (StringUtils.isNotBlank(name)) {
			name = "%" + name + "%";
			map.put("name", name);
		}
		if (StringUtils.isNotBlank(optChannel)) {
			optChannel = "%" + optChannel + "%";
			map.put("optChannel", optChannel);
		}
		map.put("startTime", startTime);
		map.put("endTime", endTime);
		return optRecordMapper.appselectByParams(map);
	}

	@Override
	public boolean insert(OptRecord optRecord) {
		if (optRecord.getInsertTime() == null) {
			optRecord.setInsertTime(new Date());
		}
		return optRecordMapper.insert(optRecord) > 0;
	}
	@Override
	public boolean appInsert(AppOptRecord appOptRecord) {
		if (appOptRecord.getInsertTime() == null) {
			appOptRecord.setInsertTime(new Date());
		}
		return optRecordMapper.appInsert(appOptRecord) > 0;
	}

}
